package shc.graduation.utils;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public class SharePreferenceUtil {
    private final int MODE_WORLD_READABLE = 1;
    Context context;
    private SharedPreferences sp;
    private Editor editor;

    // key
    private static final String IS_SAVE_PAOWANG_GROUP = "paowang_group";
    private static final String IS_SAVE_PAPER_GROUP = "paper_group";

    @SuppressLint("WorldReadableFiles")
    private SharePreferenceUtil(Context context) {
        this.context = context;
        sp = context.getSharedPreferences("GPSSimulation", MODE_WORLD_READABLE);
        editor = sp.edit();
    }

    private static SharePreferenceUtil appSPUtil = null;

    public static SharePreferenceUtil getInstance(Context context) {
        if (appSPUtil == null) {
            appSPUtil = new SharePreferenceUtil(context);
        }
        return appSPUtil;
    }

    public void savePaowangGroup(boolean isSave) {
        editor.putBoolean(IS_SAVE_PAOWANG_GROUP, isSave);
        editor.commit();
    }

    public boolean isPaoWangGroupSave() {
        return sp.getBoolean(IS_SAVE_PAOWANG_GROUP, false);
    }

    public void savePaperGroup(boolean isSave) {
        editor.putBoolean(IS_SAVE_PAPER_GROUP, isSave);
        editor.commit();
    }

    public boolean isPaperGroupSave() {
        return sp.getBoolean(IS_SAVE_PAPER_GROUP, false);
    }
}